package Example.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import annoations.ThreadSafe;

/**
 * @author Wang Renlei
 * @Date 2020/7/2
 */
@ThreadSafe
public class ImmutableExample3 {

    private final static ImmutableList<Integer> list = ImmutableList.of(1, 2, 3, 4);

    private final static ImmutableSet set = ImmutableSet.copyOf(list);

    private final static ImmutableMap<Integer, Integer> map = ImmutableMap.of(1, 2);

    //换一种创建的风格
    private final static ImmutableMap<Integer, Integer> map2 = ImmutableMap
            .<Integer, Integer>builder()
            .put(2, 4)
            .build();

    public static void main(String[] args) {
//        list.add(5);
//        map.put(4, 5);

        System.out.println(map2.get(2));
    }

}
